function combineNum(len, target) {
    let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
        // 终止条件
    let res = []
    let path = []
    let used = {}
    let index = 0

    function genCombineNum(num) {
        // 终止条件
        if (num > target || path.length > len) {
            return
        }
        if (num === target && path.length === len) {
            res.push(path.slice())
            return
        }

        for (let i = index; i < arr.length; i++) {
            const item = arr[i];
            if (used[i]) {
                continue
            }
            used[i] = true
            path.push(item)
            index = i
            genCombineNum(num + item)
            path.pop()
            used[i] = false
        }
    }
    genCombineNum(0)
    return res
}

console.log(combineNum(3, 7))